package com.huajx.tuopuda.client.udp;

import com.huajx.core.udp.LocalUDPDataReciever;
import com.huajx.core.udp.LocalUDPSocketProvider;
import com.huajx.core.util.UDPUtils;
import com.huajx.util.HexUtil;

import java.io.UnsupportedEncodingException;

/**
 * @program: di-parent
 * @description:
 * @author: lisa 叶新华
 * @create: 2019-09-17 14:09
 */
public class TuopudaUdpClient {

    private static final String TAG = TuopudaUdpClient.class.getSimpleName();
//    private static final Logger logger = LoggerFactory.getLogger(TAG);

    public static void main(String[] args) throws UnsupportedEncodingException, InterruptedException {

        // 初始化本地UDP的Socket
        LocalUDPSocketProvider.getInstance().initSocket("224.0.0.5", ConfigEntity.serverUDPPort, 0);
        // 启动本地UDP监听（接收数据用的）
        LocalUDPDataReciever.getInstance().startup();
        // 循环发送数据给服务端
       /* byte[] command=new byte[]{
    		(byte)0X7E,
    		(byte)0X00, (byte)0X95,
    		(byte)0X81, (byte)0X10, 
    		(byte)0X00, (byte)0X00,
    		(byte)0X00, (byte)0X00,
    		(byte)0X00,(byte)0X00,
    		(byte)0X00,(byte)0X00,
    		(byte)0X00,(byte)0X00,
    		(byte)0X00,(byte)0X00,
    		(byte)0X00,(byte)0X00,
    		(byte)0X00,(byte)0X00,
    		(byte)0X00,(byte)0X00,
    		(byte)0X00,(byte)0X00,
    		(byte)0X00,(byte)0X00,
    		(byte)0X00,(byte)0X00,
    		(byte)0X00,(byte)0X00,
    		(byte)0X00,(byte)0X00,
    		(byte)0X18,(byte)0X02,
    		(byte)0X0D,
    		};
          while (true) {
 	  	    UDPUtils.send(command, command.length);
             Thread.sleep(5000);
          }*/
        
        Thread.sleep(5000);
        String command="7e00958110000000000000000000000000000000000000000000000000000026010d";
//        System.out.println(command);
        UDPUtils.send(HexUtil.hexToBytes(command), 34);
    
    }
    
    /**
     * 10进制转换为16进制
     */
    /*public static String convert16(long a){
  	  String str = "";
        //1:用a去除以16，得到商和余数
        Long sun = a/(16L);
        Long yuShu = a%16L;
        str = ""+shuZhiToZhiMu(String.valueOf(yuShu));
        while(sun > 0 ){
           //2：继续用商去除以16，得到商和余数
           yuShu = sun % 16;
           sun = sun / 16;         
           //3：如果商为0，那么就终止         
           //4：把所有的余数倒序排列
           str = shuZhiToZhiMu(String.valueOf(yuShu)) + str;
        }
        System.out.println("16进制==="+str);
        String str2 = "";           
        // 反转后的字符串
        if(str.length()==3){
        	str=0+str;
        }
        for (int i = str.length() - 2; i >= 0; ){
           str2 += str.substring(i, i+2);
           i=i-2;
        }
        System.out.println("16进制高低互换==="+str2);
        return str2;
    }*/
    /*private static String shuZhiToZhiMu(String a){ 
        switch(a){   //若jdk版本switch不支持String,可以将String转换为int类型后判断
           case "10" :
              return "a";
           case "11" :
             return "b";
           case "12" :
             return "c";
           case "13" :
             return "d";
           case "14" :
             return "e";    
           case "15" :
             return "f";  
        }
        return ""+a;
     }*/
    /**
     * 将板地址转换为byte[]
     * @param boardAddress
     */
    public void board (String boardAddress){
    	
    }
}